package rock.scissors.paper;

import java.util.ArrayList;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;

public class TestRockPaperScissors {
	
	RockPaperScissors rps;
	ArrayList<RPSEnum> listRock;
	ArrayList<RPSEnum> listPaper;
	ArrayList<RPSEnum> listScissors;
	
	public TestRockPaperScissors() {
		
	}

	@BeforeClass
	public void setUpClass() {
		 rps = new RockPaperScissors();
         
         listRock = new ArrayList<RPSEnum>();
         for(int i=0;i<20 ; i++)
                 listRock.add(RPSEnum.ROCK);
         listPaper = new ArrayList<RPSEnum>();
         for(int i=0;i<20 ; i++)
                 listPaper.add(RPSEnum.PAPER);
         listScissors = new ArrayList<RPSEnum>();
         for(int i=0;i<20 ; i++)
                 listScissors.add(RPSEnum.SCISSORS);
                


	}

	@AfterClass
	public void tearDownClass() {
		rps = null;
		listRock = null;
		listPaper = null;
		listScissors = null;
	}
	
	@DataProvider(name = "rand")
    public Object[][] createRandPlayer() {
     return new Object[][] {
       { new Player("1"), new Player("2") },
       { new Player("1"), new Player("2") },
       { new Player("1"), new Player("2") },
     };
    }
	
	@DataProvider(name = "win-player")
	public Object[][] createWinPlayer() {
		return new Object[][] {
				{ new Player("1",0,listRock), new Player("2",0,listScissors) },
				{ new Player("1",0,listPaper), new Player("2",0,listRock) },
				{ new Player("1",0,listScissors), new Player("2",0,listPaper) },
		};
	}
	
	@DataProvider(name = "tie-player")
	public Object[][] createTiePlayer() {
		return new Object[][] {
				{ new Player("1",0,listRock), new Player("2",0,listRock) },
				{ new Player("1",0,listPaper), new Player("2",0,listPaper) },
				{ new Player("1",0,listScissors), new Player("2",0,listScissors) },
		};
	}
	
	@DataProvider(name = "lost-player")
	public Object[][] createLostPlayer() {
		return new Object[][] {
				{ new Player("1",0,listRock), new Player("2",0,listPaper) },
				{ new Player("1",0,listPaper), new Player("2",0,listScissors) },
				{ new Player("1",0,listScissors), new Player("2",0,listRock) },
		};
	}
	
	@DataProvider(name = "win")
	public Object[][] createWinData() {
		return new Object[][] {
				{ "ROCK", "SCISSORS" },
				{ "PAPER","ROCK" },
				{ "SCISSORS","PAPER" },
		};
	}
	
	@DataProvider(name = "lost")
	public Object[][] createLostData() {
		return new Object[][] {
				{ "ROCK", "PAPER" },
				{ "PAPER","SCISSORS" },
				{ "SCISSORS","ROCK" },
		};
	}
	
	@DataProvider(name = "tie")
	public Object[][] createTieData() {
		return new Object[][] {
				{ "ROCK", "ROCK" },
				{ "PAPER","PAPER" },
				{ "SCISSORS","SCISSORS" },
		};
	}
	
	@Test(dataProvider = "win")
	void testWinPlay(String p1, String p2)
	{
		Assert.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)),Result.WIN);
	}
	
	@Test(dataProvider = "tie")
	void testTiePlay(String p1, String p2)
	{
		Assert.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)),Result.TIE);
	}
	
	@Test(dataProvider = "lost")
	void testLostPlay(String p1, String p2)
	{
		Assert.assertEquals(rps.play(RPSEnum.valueOf(p1), RPSEnum.valueOf(p2)),Result.LOST);
	}
	
	@Test(dataProvider = "win-player")
    void testWinPlayer(Player p1, Player p2){
           
            Assert.assertEquals(rps.play(p1, p2),Result.WIN);
    }
   
    @Test(dataProvider = "lost-player")
    void testLostPlayer(Player p1, Player p2){
           
            Assert.assertEquals(rps.play(p1, p2),Result.LOST);
    }
   
    @Test(dataProvider = "tie-player")
    void testTiePlayer(Player p1, Player p2){
           
            Assert.assertEquals(rps.play(p1, p2),Result.TIE);
    }
   
    @Test(dataProvider = "rand")
    void testRandPlayer(Player p1, Player p2){
           
            Assert.assertEquals(rps.play(p1, p2),Result.TIE);
    }
}
